package com.csw.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicExchangeBindingQueue {
    private static final String PREFIX = "test002";
    //模糊匹配，“*”匹配一个单词，“#”匹配多个单词
    public static final String ROUTE_KEY_YGZS_POST_INSERT = PREFIX + "ygzsPostInsert.topic";
    public static final String YGZS_POST_INSERT_QUEUE_NAME = PREFIX + "ygzsPostInsertQueue";
    public static final String YGZS_POST_INSERT_QUEUE_EXCHANGE_NAME = PREFIX + "YgzsPostInsertExchange";

    //新版员工之声帖子插入队列绑定
    @Bean(YGZS_POST_INSERT_QUEUE_NAME)
    public Queue ygzsPostInsertQueue() {
        return new Queue(YGZS_POST_INSERT_QUEUE_NAME);
    }

    //新版员工之声帖子插入交换机绑定
    @Bean(name = YGZS_POST_INSERT_QUEUE_EXCHANGE_NAME)
    public TopicExchange ygzsPostInsertExchange() {
        return new TopicExchange(YGZS_POST_INSERT_QUEUE_EXCHANGE_NAME, true, false);
    }

    //新版员工知识帖子插入队列绑定
    @Bean
    public Binding topicExchangeBindingQueueYgzsPostInsert(@Qualifier(YGZS_POST_INSERT_QUEUE_NAME) Queue noticeQueue,
                                                           @Qualifier(YGZS_POST_INSERT_QUEUE_EXCHANGE_NAME) TopicExchange topicExchange) {
        return BindingBuilder.bind(noticeQueue).to(topicExchange).with(ROUTE_KEY_YGZS_POST_INSERT);
    }
}
